package com.ssh;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class ReverseVowels_345 {
	@Test
	public void test() {
		System.out.println(reverseVowels("leetcode"));
	}
	
	
	public String reverseVowels(String s) {
		StringBuffer s1 = new StringBuffer(s);
        Set<Character> set = new HashSet<Character>(Arrays.asList('a','e','i','o','u','A','E','I','O','U'));
        int lo = 0,hi = s.length()-1;
        while (lo < hi) {
        	char c1 = s.charAt(lo);
        	char c2 = s.charAt(hi);
        	if (set.contains(c1) && set.contains(c2)) {
        		s1.setCharAt(lo, c2);
        		s1.setCharAt(hi, c1);
        		lo++;
        		hi--;
        	}else if (!set.contains(c1)) {
        		lo++;
        	}else if (!set.contains(c2)) {
        		hi--;
        	}else {
        		lo++;
        		hi--;
        	}
        }
        return s1.toString();
    }
}
